package com.sky.controller.user;

import com.sky.constant.RedisConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController("userShopController")//由于用户端和管理端都有ShopController，所以必须分别取不同的名字，避免bean同名
@RequestMapping("/user/shop")
@Api(tags = "店铺营业状态查询和修改")
@Slf4j
public class ShopController {
    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/status")
    @ApiOperation("获取店铺营业状态接口")
    public Result<Integer> getStatus() {
        log.info("获取店铺营业状态");
        ValueOperations valueOperations = redisTemplate.opsForValue();
        //向redis存储数据和取出数据时必须使用相同的类型，即存入一个Integer，取出时才能强转为Integer
        Integer shopStatus = (Integer)valueOperations.get(RedisConstant.SHOP_STATUS);
        return Result.success(shopStatus);
    }
}
